<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>计数器</title>
    <style>
        #count{
            width: 420px;
            height: 100px;
            margin: 100px;
            box-shadow: 4px 4px 4px #888;
            border:1px solid #ccc;
        }
        button{
            width: 150px;
            height: 100px;
            border: none;
            background-color: #ccc;
            color: #fff;
            font-size: 50px;
        }
        span{
            font-size: 30px;
            margin-left: 40px;
        }
        button.r{
            float: right;
        }
    </style>
</head>

<body>
    <div id="count">
        <button @click="sub">-</button>
        <span>{{num}}</span>
        <button class="r" @click="add">+</button>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        var count=new Vue({
            el:"#count",
            data:{
                num:1
            },
            methods:{
                sub:function(){
                    if(this.num>0)
                    {
                        this.num--;
                    }else{
                        alert("别点了，到底了")
                    }
                },
                add:function(){
                    if(this.num<10)
                    {
                        this.num++;
                    }else{
                        alert("别点了，到头了");
                    }
                }
            }
        })
    </script>
</body>
</html>